package com.clstu.generic;

import java.util.*;

public class GenericExercise {
    public static void main(String[] args) {
        Student student = new Student("jack");
        Student student1 = new Student("mary");
        Student student2 = new Student("john");
        HashSet<Student> students = new HashSet<>();
        students.add(student);
        students.add(student1);
        students.add(student2);
        System.out.println("============foreach======");
        for (Student s:students
             ) {
            System.out.println(s);
        }
        System.out.println("=========iterator==========");
        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()) {
            Student next =  iterator.next();
            System.out.println(next);
        }

        HashMap<String, Student> map = new HashMap<>();
        map.put("s1",student);
        map.put("s2",student1);
        map.put("s3",student2);
        Set<Map.Entry<String,Student>> set=map.entrySet();
        System.out.println("========foreach");
        for (Map.Entry e:set
             ) {
            System.out.println(e.getKey()+"------"+e.getValue());
        }
        System.out.println("=======keySet======");
        Set<String> keySet = map.keySet();
        for (String s:keySet
             ) {
            System.out.println(s+"======"+map.get(s));
        }


    }

}

class Student{
    private String name;

    public Student(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                '}';
    }
}